<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_hids_keyboard/main.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('nrf6310__nrf2752_2ble_2ble__app__hids__keyboard_2main_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_hids_keyboard/main.c</div>  </div>
</div>
<div class="contents">
<a href="nrf6310__nrf2752_2ble_2ble__app__hids__keyboard_2main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;<a class="code" href="nordic__common_8h.html" title="Common defines and macros for firmware developed by Nordic Semiconductor.">nordic_common.h</a>&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;nrf.h&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="nrf__assert_8h.html" title="Utilities for verifying program logic.">nrf_assert.h</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;nrf_error.h&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;nrf51_bitfields.h&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;ble.h&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="ble__advdata_8h.html">ble_advdata.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="ble__hids_8h.html">ble_hids.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="ble__bas_8h.html">ble_bas.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;<a class="code" href="ble__dis_8h.html">ble_dis.h</a>&quot;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;<a class="code" href="ble__conn__params_8h.html">ble_conn_params.h</a>&quot;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;<a class="code" href="ble__nrf6310__pins_8h.html">ble_nrf6310_pins.h</a>&quot;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &quot;<a class="code" href="ble__sensorsim_8h.html">ble_sensorsim.h</a>&quot;</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include &quot;<a class="code" href="app__scheduler_8h.html">app_scheduler.h</a>&quot;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &quot;app_scheduler_cfg.h&quot;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &quot;<a class="code" href="ble__stack__handler_8h.html">ble_stack_handler.h</a>&quot;</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &quot;<a class="code" href="app__timer_8h.html">app_timer.h</a>&quot;</span>
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga81bb5458ad79486e6aefb2286239b760">00054</a> <span class="preprocessor">#define KEY_PRESS_BUTTON_PIN_NO          NRF6310_BUTTON_0                   </span>
<a name="l00055"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5d49591a87319c84e9963e355aa66e50">00055</a> <span class="preprocessor">#define CAPS_ON_LED_PIN_NO               NRF6310_LED_2                      </span>
<a name="l00057"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">00057</a> <span class="preprocessor">#define DEVICE_NAME                      &quot;Keyboard_0.1&quot;                     </span>
<a name="l00058"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaaa2b8f5b105c3019df0cb346f472e803">00058</a> <span class="preprocessor">#define MANUFACTURER_NAME                &quot;NordicSemiconductor&quot;              </span>
<a name="l00060"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">00060</a> <span class="preprocessor">#define BATTERY_LEVEL_MEAS_INTERVAL      2000                               </span>
<a name="l00061"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga59eb06cba38be11278ebd2829e95bc26">00061</a> <span class="preprocessor">#define MIN_BATTERY_LEVEL                81                                 </span>
<a name="l00062"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga16896fb7a69ca90a4a4e341d5a888002">00062</a> <span class="preprocessor">#define MAX_BATTERY_LEVEL                100                                </span>
<a name="l00063"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga69eef02165834e4dabc5757b82dddbf1">00063</a> <span class="preprocessor">#define BATTERY_LEVEL_INCREMENT          1                                  </span>
<a name="l00065"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadcf82f097b1063d2184008f34044d6f8">00065</a> <span class="preprocessor">#define PNP_ID_VENDOR_ID_SOURCE          0x02                               </span>
<a name="l00066"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gac294f76c25d54a7144acb2d839f05785">00066</a> <span class="preprocessor">#define PNP_ID_VENDOR_ID                 0x1915                             </span>
<a name="l00067"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga136d0bff35b1ea2dcf2889f6f700971d">00067</a> <span class="preprocessor">#define PNP_ID_PRODUCT_ID                0xEEEE                             </span>
<a name="l00068"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6778c118c0d9848c00ceeb23759aec6f">00068</a> <span class="preprocessor">#define PNP_ID_PRODUCT_VERSION           0x0001                             </span>
<a name="l00070"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">00070</a> <span class="preprocessor">#define APP_ADV_INTERVAL                 64                                 </span>
<a name="l00071"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf58371bad8e1be8e2323df60379ed2df">00071</a> <span class="preprocessor">#define APP_ADV_TIMEOUT_IN_SECONDS       180                                </span>
<a name="l00073"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga95196d5d0f40cf195a6001955d6d98cf">00073</a> <span class="preprocessor">#define MIN_CONN_INTERVAL                6                                  </span>
<a name="l00074"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7d868ed8adb7d475b463fd8855907a18">00074</a> <span class="preprocessor">#define MAX_CONN_INTERVAL                24                                 </span>
<a name="l00075"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga0c921a874ac37870fc1516ce66cd228a">00075</a> <span class="preprocessor">#define SLAVE_LATENCY                    6                                  </span>
<a name="l00076"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga799412c2b531ca347e13611e6e7523b9">00076</a> <span class="preprocessor">#define CONN_SUP_TIMEOUT                 (3 * 100)                          </span>
<a name="l00077"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">00077</a> <span class="preprocessor">#define FIRST_CONN_PARAMS_UPDATE_DELAY   (5 * 1000)                         </span>
<a name="l00078"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadf85796ef07632ed27e0bce9509d9245">00078</a> <span class="preprocessor">#define NEXT_CONN_PARAMS_UPDATE_DELAY    (30 * 1000)                        </span>
<a name="l00079"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">00079</a> <span class="preprocessor">#define MAX_CONN_PARAMS_UPDATE_COUNT     3                                  </span>
<a name="l00081"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7c1fffb0f865552108560d4c63b32db1">00081</a> <span class="preprocessor">#define SEC_PARAM_TIMEOUT                60                                 </span>
<a name="l00082"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gacbf03a82593c273743a5a80a1119b851">00082</a> <span class="preprocessor">#define SEC_PARAM_BOND                   1                                  </span>
<a name="l00083"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab6831ebe113f8afe970326b7742b5947">00083</a> <span class="preprocessor">#define SEC_PARAM_MITM                   0                                  </span>
<a name="l00084"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga42df85b3a4083cdc614d9111d580d98f">00084</a> <span class="preprocessor">#define SEC_PARAM_IO_CAPABILITIES        BLE_GAP_IO_CAPS_NONE               </span>
<a name="l00085"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">00085</a> <span class="preprocessor">#define SEC_PARAM_OOB                    0                                  </span>
<a name="l00086"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">00086</a> <span class="preprocessor">#define SEC_PARAM_MIN_KEY_SIZE           7                                  </span>
<a name="l00087"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf2cd1595de153ea1d6d843619a1a7707">00087</a> <span class="preprocessor">#define SEC_PARAM_MAX_KEY_SIZE           16                                 </span>
<a name="l00089"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga99efaf34830368d0abd515e02247c2c7">00089</a> <span class="preprocessor">#define OUTPUT_REPORT_INDEX              0                                  </span>
<a name="l00090"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga618a599e2a493e7e5e21ec6712eab629">00090</a> <span class="preprocessor">#define OUTPUT_REPORT_MAX_LEN            1                                  </span>
<a name="l00091"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga457a0e46397da8d5efadd01f8709ba24">00091</a> <span class="preprocessor">#define INPUT_REPORT_KEYS_INDEX          0                                  </span>
<a name="l00092"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gae4da404b343c895fbbb187de7c9d5d8e">00092</a> <span class="preprocessor">#define OUTPUT_REPORT_BIT_MASK_CAPS_LOCK 0x02                               </span>
<a name="l00094"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga86d9879e1f1e698d670d31c933e5fe95">00094</a> <span class="preprocessor">#define BASE_USB_HID_SPEC_VERSION        0x0101                             </span>
<a name="l00096"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">00096</a> <span class="preprocessor">static ble_hids_t                        s_hids;                            </span>
<a name="l00097"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">00097</a> <span class="preprocessor">static ble_bas_t                         s_bas;                             </span>
<a name="l00098"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">00098</a> <span class="preprocessor">static ble_gap_sec_params_t              s_sec_params;                      </span>
<a name="l00099"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gade286b62fde8822965f1e5740a2e9544">00099</a> <span class="preprocessor">static bool                              s_in_boot_mode = false;            </span>
<a name="l00101"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">00101</a> <span class="preprocessor">static ble_sensorsim_cfg_t               s_battery_sim_cfg;                 </span>
<a name="l00102"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">00102</a> <span class="preprocessor">static ble_sensorsim_state_t             s_battery_sim_state;               </span>
<a name="l00104"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa3b8fdf1e5fd735cc1a297820f750f46">00104</a> <span class="preprocessor">static uint8_t s_sample_key_press_pattern[] =                               </span>
<a name="l00105"></a>00105 <span class="preprocessor">{</span>
<a name="l00106"></a>00106 <span class="preprocessor"></span>    0x00, <span class="comment">/* Modifier status byte */</span>
<a name="l00107"></a>00107     0x00, <span class="comment">/* Reserved 0x00 */</span>
<a name="l00108"></a>00108     0x0b, <span class="comment">/* Key h */</span>
<a name="l00109"></a>00109     0x08, <span class="comment">/* Key e */</span>
<a name="l00110"></a>00110     0x0f, <span class="comment">/* Key l */</span>
<a name="l00111"></a>00111     0x0f, <span class="comment">/* Key l */</span>
<a name="l00112"></a>00112     0x12, <span class="comment">/* Key o */</span>
<a name="l00113"></a>00113     0x28  <span class="comment">/* Key Return */</span>
<a name="l00114"></a>00114 };
<a name="l00115"></a>00115 
<a name="l00116"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf4f08291880f002aa1739475ff1f64cb">00116</a> <span class="keyword">static</span> uint8_t <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf4f08291880f002aa1739475ff1f64cb">s_caps_on_key_pattern</a>[] =                                    
<a name="l00117"></a>00117 {
<a name="l00118"></a>00118     0x00, <span class="comment">/* Modifier status byte */</span>
<a name="l00119"></a>00119     0x00, <span class="comment">/* Reserved 0x00 */</span>
<a name="l00120"></a>00120     0x06, <span class="comment">/* Key C */</span>
<a name="l00121"></a>00121     0x04, <span class="comment">/* Key a */</span>
<a name="l00122"></a>00122     0x13, <span class="comment">/* Key p */</span>
<a name="l00123"></a>00123     0x16, <span class="comment">/* Key s */</span>
<a name="l00124"></a>00124     0x12, <span class="comment">/* Key o */</span>
<a name="l00125"></a>00125     0x11  <span class="comment">/* Key n */</span>
<a name="l00126"></a>00126 };
<a name="l00127"></a>00127 
<a name="l00128"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad755d5a2e1c883ec7fc9548a369049cb">00128</a> <span class="keyword">static</span> uint8_t <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad755d5a2e1c883ec7fc9548a369049cb">s_caps_off_key_pattern</a>[] =                                   
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130     0x00, <span class="comment">/* Modifier status byte */</span>
<a name="l00131"></a>00131     0x00, <span class="comment">/* Reserved 0x00 */</span>
<a name="l00132"></a>00132     0x06, <span class="comment">/* Key C */</span>
<a name="l00133"></a>00133     0x04, <span class="comment">/* Key a */</span>
<a name="l00134"></a>00134     0x13, <span class="comment">/* Key p */</span>
<a name="l00135"></a>00135     0x16, <span class="comment">/* Key s */</span>
<a name="l00136"></a>00136     0x12, <span class="comment">/* Key o */</span>
<a name="l00137"></a>00137     0x09  <span class="comment">/* Key f */</span>
<a name="l00138"></a>00138 };
<a name="l00139"></a>00139 
<a name="l00140"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga9ab7810eac80900e57304488a0410a50">00140</a> <span class="preprocessor">#define INPUT_REPORT_KEYS_MAX_LEN           \</span>
<a name="l00141"></a>00141 <span class="preprocessor">    MAX(MAX(sizeof(s_caps_off_key_pattern), \</span>
<a name="l00142"></a>00142 <span class="preprocessor">            sizeof(s_caps_on_key_pattern)), \</span>
<a name="l00143"></a>00143 <span class="preprocessor">        sizeof(s_sample_key_press_pattern))                                 </span>
<a name="l00145"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga879ae27a78496d2725f8b8d0481baa38">00145</a> <span class="preprocessor">static uint8_t s_sample_key_release_pattern[INPUT_REPORT_KEYS_MAX_LEN] =    </span>
<a name="l00146"></a>00146 <span class="preprocessor">{ </span>
<a name="l00147"></a>00147 <span class="preprocessor"></span>    0x00
<a name="l00148"></a>00148 };
<a name="l00149"></a>00149 
<a name="l00150"></a>00150 
<a name="l00151"></a>00151 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaacd557e6bc45d33880a272b051f7684e" title="HID event handler.">on_hids_evt</a>(<a class="code" href="structble__hids__s.html" title="HID Service structure. This contains various status information for the service.">ble_hids_t</a> * p_hids, <a class="code" href="structble__hids__evt__t.html" title="HID Service event.">ble_hids_evt_t</a> * p_evt);
<a name="l00152"></a>00152 
<a name="l00153"></a>00153 
<a name="l00161"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadec561788a76b8a63ad9663625a25d78">00161</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#gadec561788a76b8a63ad9663625a25d78" title="Assert macro callback function.">assert_nrf_callback</a>(uint16_t line_num, <span class="keyword">const</span> uint8_t * file_name)
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163     <span class="comment">// Copying parameters to static variables because parameters are not accessible in debugger</span>
<a name="l00164"></a>00164     <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t  s_file_name[128];      
<a name="l00165"></a>00165     <span class="keyword">static</span> <span class="keyword">volatile</span> uint16_t s_line_num;
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     strcpy((<span class="keywordtype">char</span> *)s_file_name, (<span class="keyword">const</span> <span class="keywordtype">char</span> *)file_name);
<a name="l00168"></a>00168     s_line_num = line_num;
<a name="l00169"></a>00169     UNUSED_VARIABLE(s_file_name);
<a name="l00170"></a>00170     UNUSED_VARIABLE(s_line_num);
<a name="l00171"></a>00171     
<a name="l00172"></a>00172     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ASSERT_LED_PIN_NO);
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     <span class="keywordflow">for</span> (;;)
<a name="l00175"></a>00175     {
<a name="l00176"></a>00176         <span class="comment">// Loop forever. On assert, the system can only recover on reset</span>
<a name="l00177"></a>00177     }
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 
<a name="l00188"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga54ab546c90d69e5fc9cfee653024ea53">00188</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga54ab546c90d69e5fc9cfee653024ea53" title="Service error handler.">service_error_handler</a>(uint32_t nrf_error)
<a name="l00189"></a>00189 {
<a name="l00190"></a>00190     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00191"></a>00191 }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193 
<a name="l00196"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab155022684d4acfd98218c3799822e74">00196</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab155022684d4acfd98218c3799822e74" title="Perform battery measurement, and update Battery Level characteristic in Battery Service.">battery_level_update</a>(<span class="keywordtype">void</span>)
<a name="l00197"></a>00197 {
<a name="l00198"></a>00198     uint32_t err_code;
<a name="l00199"></a>00199     uint8_t  battery_level;
<a name="l00200"></a>00200 
<a name="l00201"></a>00201     battery_level = (uint8_t)<a class="code" href="group__ble__sdk__lib__sensorsim.html#gae73b8f0f956e0708e16d160605318ba8" title="Generate a simulated sensor measurement using a triangular waveform generator.">ble_sensorsim_measure</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">s_battery_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>);
<a name="l00202"></a>00202 
<a name="l00203"></a>00203     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#ga58d8f4336cce49ea5b3a2f8997bfe00e" title="Update battery level.">ble_bas_battery_level_update</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, battery_level);
<a name="l00204"></a>00204     <span class="keywordflow">if</span> (
<a name="l00205"></a>00205         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>) 
<a name="l00206"></a>00206         &amp;&amp; 
<a name="l00207"></a>00207         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>) 
<a name="l00208"></a>00208         &amp;&amp; 
<a name="l00209"></a>00209         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00210"></a>00210         &amp;&amp;
<a name="l00211"></a>00211         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00212"></a>00212     )
<a name="l00213"></a>00213     {
<a name="l00214"></a>00214         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00215"></a>00215     }
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 
<a name="l00225"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155">00225</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00226"></a>00226 {
<a name="l00227"></a>00227     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_BATTERY_LEVEL_MEAS);
<a name="l00228"></a>00228     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab155022684d4acfd98218c3799822e74" title="Perform battery measurement, and update Battery Level characteristic in Battery Service.">battery_level_update</a>();
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230 
<a name="l00231"></a>00231 
<a name="l00236"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga0892e076b365fc49b55bd0f90ab09222">00236</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>(<span class="keywordtype">void</span>)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ADVERTISING_LED_PIN_NO);
<a name="l00239"></a>00239     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(CONNECTED_LED_PIN_NO);
<a name="l00240"></a>00240     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ASSERT_LED_PIN_NO);
<a name="l00241"></a>00241     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5d49591a87319c84e9963e355aa66e50">CAPS_ON_LED_PIN_NO</a>);
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 
<a name="l00244"></a>00244 
<a name="l00249"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga09658aaa0774820d8f25249d551bc283">00249</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>(<span class="keywordtype">void</span>)
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251     uint32_t err_code;
<a name="l00252"></a>00252 
<a name="l00253"></a>00253     <span class="comment">// Initialize timer module, making it use the scheduler</span>
<a name="l00254"></a>00254     err_code = <a class="code" href="group__app__timer.html#ga4e1da5a2f64ee78ee97f7422ea97e439" title="Initializes the timer module.">app_timer_init</a>(<a class="code" href="group__app__scheduler.html#gad09181e10ae224ca354b5e650b5e3a0a" title="Schedules a timer event.">app_sched_timer_event_schedule</a>);
<a name="l00255"></a>00255     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00256"></a>00256     {
<a name="l00257"></a>00257         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00258"></a>00258     }
<a name="l00259"></a>00259 }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261 
<a name="l00267"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga1004973353f351806e42896c491a5ab2">00267</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00268"></a>00268 {
<a name="l00269"></a>00269     uint32_t                err_code;
<a name="l00270"></a>00270     <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>   gap_conn_params;
<a name="l00271"></a>00271     <a class="code" href="structble__gap__conn__sec__mode__t.html" title="GAP link requirements.">ble_gap_conn_sec_mode_t</a> sec_mode;
<a name="l00272"></a>00272 
<a name="l00273"></a>00273     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;sec_mode);
<a name="l00274"></a>00274 
<a name="l00275"></a>00275     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga7d665aa56f8d248b8779a6cf170e2052" title="Set GAP device name.">ble_gap_device_name_set</a>(&amp;sec_mode, <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">DEVICE_NAME</a>);
<a name="l00276"></a>00276     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00277"></a>00277     {
<a name="l00278"></a>00278         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00279"></a>00279     }
<a name="l00280"></a>00280 
<a name="l00281"></a>00281     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga711f129fb97e0071ab04d2e994125f7a" title="Set GAP Appearance field.">ble_gap_appearance_set</a>(<a class="code" href="group___b_l_e___a_p_p_e_a_r_a_n_c_e_s.html#gae9bff713685aad5a895f18f7849e455a">BLE_APPEARANCE_KEYBOARD_HID_SUBTYPE</a>);
<a name="l00282"></a>00282     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00283"></a>00283     {
<a name="l00284"></a>00284         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00285"></a>00285     }
<a name="l00286"></a>00286 
<a name="l00287"></a>00287     memset(&amp;gap_conn_params, 0, <span class="keyword">sizeof</span>(gap_conn_params));
<a name="l00288"></a>00288 
<a name="l00289"></a>00289     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#ac927a642ee2203f875fcce1eabb5fa64">min_conn_interval</a> = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga95196d5d0f40cf195a6001955d6d98cf">MIN_CONN_INTERVAL</a>;
<a name="l00290"></a>00290     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7d868ed8adb7d475b463fd8855907a18">MAX_CONN_INTERVAL</a>;
<a name="l00291"></a>00291     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a39219ac00a0e8ed843ee32b9df8be11e">slave_latency</a>     = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga0c921a874ac37870fc1516ce66cd228a">SLAVE_LATENCY</a>;
<a name="l00292"></a>00292     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a2089e7fb26f6b24882d1437eb5553bc7">conn_sup_timeout</a>  = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga799412c2b531ca347e13611e6e7523b9">CONN_SUP_TIMEOUT</a>;
<a name="l00293"></a>00293 
<a name="l00294"></a>00294     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga28e0062141d77d7b2272fc3a6b6e17c5" title="Set GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_set</a>(&amp;gap_conn_params);
<a name="l00295"></a>00295     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00296"></a>00296     {
<a name="l00297"></a>00297         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00298"></a>00298     }
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300 
<a name="l00301"></a>00301 
<a name="l00307"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga935c9624de0709fe228dbefa4b54de48">00307</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>(<span class="keywordtype">void</span>)
<a name="l00308"></a>00308 {
<a name="l00309"></a>00309     uint32_t      err_code;
<a name="l00310"></a>00310     <a class="code" href="structble__advdata__t.html" title="Advertising data structure. This contains all options and data needed for encoding and setting the ad...">ble_advdata_t</a> advdata;
<a name="l00311"></a>00311     uint8_t       flags = <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga5c5243da93bae524088eefd608656012">BLE_GAP_DISC_MODE_LIMITED</a> | <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga346a5b47f4b8f94a08f320a0d8c14c18">BLE_GAP_DISC_BR_EDR_NOT_SUPPORTED</a>;
<a name="l00312"></a>00312 
<a name="l00313"></a>00313     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> adv_uuids[] = { { <a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gaafd551131de655ea5987ed148170bf2d">BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE</a>, <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a> } };
<a name="l00314"></a>00314 
<a name="l00315"></a>00315     <span class="comment">// Build and set advertising data</span>
<a name="l00316"></a>00316     memset(&amp;advdata, 0, <span class="keyword">sizeof</span>(advdata));
<a name="l00317"></a>00317 
<a name="l00318"></a>00318     advdata.<a class="code" href="structble__advdata__t.html#a045ec5915c094e107ac24d185b83fa49">name_type</a>               = <a class="code" href="group__ble__sdk__lib__advdata.html#gga03c5ccf232779001be9786021b1a563ba63a26e22b9d6a0899edac755d0e2f488">BLE_ADVDATA_FULL_NAME</a>;
<a name="l00319"></a>00319     advdata.<a class="code" href="structble__advdata__t.html#aff2bb3e4016b9a7b6cbcdd6e98feb719">include_appearance</a>      = <span class="keyword">true</span>;
<a name="l00320"></a>00320     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#aaba88b24a21a6c70c895c0d55f4a69a0">size</a>              = <span class="keyword">sizeof</span>(flags);
<a name="l00321"></a>00321     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>            = &amp;flags;
<a name="l00322"></a>00322     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a1cecc52d144b939f33a67c1d68363e99">uuid_cnt</a> = <span class="keyword">sizeof</span>(adv_uuids) / <span class="keyword">sizeof</span>(adv_uuids[0]);
<a name="l00323"></a>00323     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a100265d2ed10e66a76e53cba205dc8a3">p_uuids</a>  = adv_uuids;
<a name="l00324"></a>00324 
<a name="l00325"></a>00325     err_code = <a class="code" href="group__ble__sdk__lib__advdata.html#ga180ff4057a0763688c734e98ab8d976b" title="Encodes and sets the advertising data and/or scan response data.">ble_advdata_set</a>(&amp;advdata, NULL);
<a name="l00326"></a>00326     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00327"></a>00327     {
<a name="l00328"></a>00328         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00329"></a>00329     }
<a name="l00330"></a>00330 }
<a name="l00331"></a>00331 
<a name="l00332"></a>00332 
<a name="l00335"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga2d0743f12929b17b64c5c2fb101a9350">00335</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga2d0743f12929b17b64c5c2fb101a9350" title="Initialize Device Information Service.">dis_init</a>(<span class="keywordtype">void</span>)
<a name="l00336"></a>00336 {
<a name="l00337"></a>00337     uint32_t         err_code;
<a name="l00338"></a>00338     <a class="code" href="structble__dis__init__t.html" title="Device Information Service init structure. This contains all possible characteristics needed for init...">ble_dis_init_t</a>   dis_init_obj;
<a name="l00339"></a>00339     <a class="code" href="structble__dis__pnp__id__t.html" title="PnP ID parameters.">ble_dis_pnp_id_t</a> pnp_id;
<a name="l00340"></a>00340 
<a name="l00341"></a>00341     pnp_id.<a class="code" href="structble__dis__pnp__id__t.html#a60b6889d45981438b68d1de0d4d4718f">vendor_id_source</a> = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadcf82f097b1063d2184008f34044d6f8">PNP_ID_VENDOR_ID_SOURCE</a>;
<a name="l00342"></a>00342     pnp_id.<a class="code" href="structble__dis__pnp__id__t.html#abd60aba7846c925f784c3e89e2f54e45">vendor_id</a>        = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gac294f76c25d54a7144acb2d839f05785">PNP_ID_VENDOR_ID</a>;
<a name="l00343"></a>00343     pnp_id.<a class="code" href="structble__dis__pnp__id__t.html#a215e5feaef08c77d8e9f17ab421e8a66">product_id</a>       = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga136d0bff35b1ea2dcf2889f6f700971d">PNP_ID_PRODUCT_ID</a>;
<a name="l00344"></a>00344     pnp_id.<a class="code" href="structble__dis__pnp__id__t.html#add66cd1e2fe782e92652f5f53cef73c8">product_version</a>  = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6778c118c0d9848c00ceeb23759aec6f">PNP_ID_PRODUCT_VERSION</a>;
<a name="l00345"></a>00345 
<a name="l00346"></a>00346     memset(&amp;dis_init_obj, 0, <span class="keyword">sizeof</span>(dis_init_obj));
<a name="l00347"></a>00347 
<a name="l00348"></a>00348     <a class="code" href="group__ble__sdk__srv__common.html#ga611dfcf7209a57c2e45964e8bb4c5756" title="Make UTF-8 structure refer to an ASCII string.">ble_srv_ascii_to_utf8</a>(&amp;dis_init_obj.<a class="code" href="structble__dis__init__t.html#a02a650cde3f65fc67f65b5fb4cd33425">manufact_name_str</a>, <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaaa2b8f5b105c3019df0cb346f472e803">MANUFACTURER_NAME</a>);
<a name="l00349"></a>00349     dis_init_obj.<a class="code" href="structble__dis__init__t.html#a5b5d4c8fc2a17cfa2e94e1c0b55f3672">p_pnp_id</a> = &amp;pnp_id;
<a name="l00350"></a>00350 
<a name="l00351"></a>00351     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;dis_init_obj.<a class="code" href="structble__dis__init__t.html#aa3268ab4659686cb4202651e071af265">dis_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00352"></a>00352     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;dis_init_obj.<a class="code" href="structble__dis__init__t.html#aa3268ab4659686cb4202651e071af265">dis_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00353"></a>00353 
<a name="l00354"></a>00354     err_code = <a class="code" href="group__ble__sdk__srv__dis.html#ga472c83dfe2ad977d76b664095a4991cd" title="Initialize the Device Information Service.">ble_dis_init</a>(&amp;dis_init_obj);
<a name="l00355"></a>00355     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00356"></a>00356     {
<a name="l00357"></a>00357         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00358"></a>00358     }
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 
<a name="l00361"></a>00361 
<a name="l00364"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga46507354f43dd16b32281f032e29d9c5">00364</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga46507354f43dd16b32281f032e29d9c5" title="Initialize Battery Service.">bas_init</a>(<span class="keywordtype">void</span>)
<a name="l00365"></a>00365 {
<a name="l00366"></a>00366     uint32_t       err_code;
<a name="l00367"></a>00367     <a class="code" href="structble__bas__init__t.html" title="Battery Service init structure. This contains all options and data needed for initialization of the s...">ble_bas_init_t</a> bas_init_obj;
<a name="l00368"></a>00368 
<a name="l00369"></a>00369     memset(&amp;bas_init_obj, 0, <span class="keyword">sizeof</span>(bas_init_obj));
<a name="l00370"></a>00370 
<a name="l00371"></a>00371     bas_init_obj.<a class="code" href="structble__bas__init__t.html#a3c25f96941dd8c1b92407ed2994691c6">evt_handler</a>          = NULL;
<a name="l00372"></a>00372     bas_init_obj.<a class="code" href="structble__bas__init__t.html#adbf298550acd37c0d6170e90504318ac">support_notification</a> = <span class="keyword">true</span>;
<a name="l00373"></a>00373     bas_init_obj.<a class="code" href="structble__bas__init__t.html#ac3ce984f1c066cfc0911e98fa1acdc8e">p_report_ref</a>         = NULL;
<a name="l00374"></a>00374     bas_init_obj.<a class="code" href="structble__bas__init__t.html#ae5e656df4b847b3a099792ae32676d16">initial_batt_level</a>   = 100;
<a name="l00375"></a>00375 
<a name="l00376"></a>00376     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.cccd_write_perm);
<a name="l00377"></a>00377     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00378"></a>00378     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00379"></a>00379 
<a name="l00380"></a>00380     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init_obj.<a class="code" href="structble__bas__init__t.html#a2c9724572f64316880f915bb78882de0">battery_level_report_read_perm</a>);
<a name="l00381"></a>00381 
<a name="l00382"></a>00382     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#gacb8ac9205dcec39e216575c76261c807" title="Initialize the Battery Service.">ble_bas_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, &amp;bas_init_obj);
<a name="l00383"></a>00383     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00384"></a>00384     {
<a name="l00385"></a>00385         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00386"></a>00386     }
<a name="l00387"></a>00387 }
<a name="l00388"></a>00388 
<a name="l00389"></a>00389 
<a name="l00392"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga1469fa1057d51643d5b64abadf23e135">00392</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga1469fa1057d51643d5b64abadf23e135" title="Initialize HID Service.">hids_init</a>(<span class="keywordtype">void</span>)
<a name="l00393"></a>00393 {
<a name="l00394"></a>00394     uint32_t                   err_code;
<a name="l00395"></a>00395     <a class="code" href="structble__hids__init__t.html" title="HID Service init structure. This contains all options and data needed for initialization of the servi...">ble_hids_init_t</a>            hids_init_obj;
<a name="l00396"></a>00396     <a class="code" href="structble__hids__inp__rep__init__t.html" title="HID Service Input Report characteristic init structure. This contains all options and data needed for...">ble_hids_inp_rep_init_t</a>    input_report_array[1];
<a name="l00397"></a>00397     <a class="code" href="structble__hids__inp__rep__init__t.html" title="HID Service Input Report characteristic init structure. This contains all options and data needed for...">ble_hids_inp_rep_init_t</a>  * p_input_report;
<a name="l00398"></a>00398     <a class="code" href="structble__hids__outp__rep__init__t.html" title="HID Service Output Report characteristic init structure. This contains all options and data needed fo...">ble_hids_outp_rep_init_t</a>   output_report_array[1];
<a name="l00399"></a>00399     <a class="code" href="structble__hids__outp__rep__init__t.html" title="HID Service Output Report characteristic init structure. This contains all options and data needed fo...">ble_hids_outp_rep_init_t</a> * p_output_report;
<a name="l00400"></a>00400     uint8_t                    hid_info_flags;
<a name="l00401"></a>00401 
<a name="l00402"></a>00402     <span class="keyword">static</span> uint8_t report_map_data[] =
<a name="l00403"></a>00403     {
<a name="l00404"></a>00404         0x05, 0x01,                 <span class="comment">// Usage Page (Generic Desktop)</span>
<a name="l00405"></a>00405         0x09, 0x06,                 <span class="comment">// Usage (Keyboard)</span>
<a name="l00406"></a>00406         0xA1, 0x01,                 <span class="comment">// Collection (Application)</span>
<a name="l00407"></a>00407         0x05, 0x07,                 <span class="comment">//     Usage Page (Key Codes)</span>
<a name="l00408"></a>00408         0x19, 0xe0,                 <span class="comment">//     Usage Minimum (224)</span>
<a name="l00409"></a>00409         0x29, 0xe7,                 <span class="comment">//     Usage Maximum (231)</span>
<a name="l00410"></a>00410         0x15, 0x00,                 <span class="comment">//     Logical Minimum (0)</span>
<a name="l00411"></a>00411         0x25, 0x01,                 <span class="comment">//     Logical Maximum (1)</span>
<a name="l00412"></a>00412         0x75, 0x01,                 <span class="comment">//     Report Size (1)</span>
<a name="l00413"></a>00413         0x95, 0x08,                 <span class="comment">//     Report Count (8)</span>
<a name="l00414"></a>00414         0x81, 0x02,                 <span class="comment">//     Input (Data, Variable, Absolute)</span>
<a name="l00415"></a>00415     
<a name="l00416"></a>00416         0x95, 0x01,                 <span class="comment">//     Report Count (1)</span>
<a name="l00417"></a>00417         0x75, 0x08,                 <span class="comment">//     Report Size (8)</span>
<a name="l00418"></a>00418         0x81, 0x01,                 <span class="comment">//     Input (Constant) reserved byte(1)</span>
<a name="l00419"></a>00419     
<a name="l00420"></a>00420         0x95, 0x05,                 <span class="comment">//     Report Count (5)</span>
<a name="l00421"></a>00421         0x75, 0x01,                 <span class="comment">//     Report Size (1)</span>
<a name="l00422"></a>00422         0x05, 0x08,                 <span class="comment">//     Usage Page (Page# for LEDs)</span>
<a name="l00423"></a>00423         0x19, 0x01,                 <span class="comment">//     Usage Minimum (1)</span>
<a name="l00424"></a>00424         0x29, 0x05,                 <span class="comment">//     Usage Maximum (5)</span>
<a name="l00425"></a>00425         0x91, 0x02,                 <span class="comment">//     Output (Data, Variable, Absolute), Led report</span>
<a name="l00426"></a>00426         0x95, 0x01,                 <span class="comment">//     Report Count (1)</span>
<a name="l00427"></a>00427         0x75, 0x03,                 <span class="comment">//     Report Size (3)</span>
<a name="l00428"></a>00428         0x91, 0x01,                 <span class="comment">//     Output (Data, Variable, Absolute), Led report padding</span>
<a name="l00429"></a>00429     
<a name="l00430"></a>00430         0x95, 0x06,                 <span class="comment">//     Report Count (6)</span>
<a name="l00431"></a>00431         0x75, 0x08,                 <span class="comment">//     Report Size (8)</span>
<a name="l00432"></a>00432         0x15, 0x00,                 <span class="comment">//     Logical Minimum (0)</span>
<a name="l00433"></a>00433         0x25, 0x65,                 <span class="comment">//     Logical Maximum (101)</span>
<a name="l00434"></a>00434         0x05, 0x07,                 <span class="comment">//     Usage Page (Key codes)</span>
<a name="l00435"></a>00435         0x19, 0x00,                 <span class="comment">//     Usage Minimum (0)</span>
<a name="l00436"></a>00436         0x29, 0x65,                 <span class="comment">//     Usage Maximum (101)</span>
<a name="l00437"></a>00437         0x81, 0x00,                 <span class="comment">//     Input (Data, Array) Key array(6 bytes)</span>
<a name="l00438"></a>00438     
<a name="l00439"></a>00439         0x09, 0x05,                 <span class="comment">//     Usage (Vendor Defined)</span>
<a name="l00440"></a>00440         0x15, 0x00,                 <span class="comment">//     Logical Minimum (0)</span>
<a name="l00441"></a>00441         0x26, 0xFF, 0x00,           <span class="comment">//     Logical Maximum (255)</span>
<a name="l00442"></a>00442         0x75, 0x08,                 <span class="comment">//     Report Count (2)</span>
<a name="l00443"></a>00443         0x95, 0x02,                 <span class="comment">//     Report Size (8 bit)</span>
<a name="l00444"></a>00444         0xB1, 0x02,                 <span class="comment">//     Feature (Data, Variable, Absolute)</span>
<a name="l00445"></a>00445 
<a name="l00446"></a>00446         0xC0                        <span class="comment">// End Collection (Application)    </span>
<a name="l00447"></a>00447     };
<a name="l00448"></a>00448 
<a name="l00449"></a>00449     <span class="comment">// Initialize HID Service</span>
<a name="l00450"></a>00450     p_input_report                      = &amp;input_report_array[<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga457a0e46397da8d5efadd01f8709ba24">INPUT_REPORT_KEYS_INDEX</a>];
<a name="l00451"></a>00451     p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a0f34a6773b9be9d0d44ebad4070b973a">writable</a>            = <span class="keyword">true</span>;
<a name="l00452"></a>00452     p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a7e8c368b285fef6796e5b0fda9b89d8c">max_len</a>             = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga9ab7810eac80900e57304488a0410a50">INPUT_REPORT_KEYS_MAX_LEN</a>;
<a name="l00453"></a>00453     p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a070c6ac5d77d97faf98946507b8f8b7b">rep_ref</a>.<a class="code" href="structble__srv__report__ref__t.html#a725a13d8d43f65c0f5e8adc271f71573">report_id</a>   = 0;
<a name="l00454"></a>00454     p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a070c6ac5d77d97faf98946507b8f8b7b">rep_ref</a>.<a class="code" href="structble__srv__report__ref__t.html#a082cbd2ab34b2f8c1afaf98b3b19fac0">report_type</a> = BLE_HIDS_REP_TYPE_INPUT;
<a name="l00455"></a>00455     
<a name="l00456"></a>00456     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a7affa6c39815d70e8fe83c9b12b9c263">attr_md</a>.cccd_write_perm);
<a name="l00457"></a>00457     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a7affa6c39815d70e8fe83c9b12b9c263">attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00458"></a>00458     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;p_input_report-&gt;<a class="code" href="structble__hids__inp__rep__init__t.html#a7affa6c39815d70e8fe83c9b12b9c263">attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00459"></a>00459 
<a name="l00460"></a>00460     p_output_report                      = &amp;output_report_array[<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga99efaf34830368d0abd515e02247c2c7">OUTPUT_REPORT_INDEX</a>];
<a name="l00461"></a>00461     p_output_report-&gt;<a class="code" href="structble__hids__outp__rep__init__t.html#a7e8c368b285fef6796e5b0fda9b89d8c">max_len</a>             = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga618a599e2a493e7e5e21ec6712eab629">OUTPUT_REPORT_MAX_LEN</a>;
<a name="l00462"></a>00462     p_output_report-&gt;<a class="code" href="structble__hids__outp__rep__init__t.html#a070c6ac5d77d97faf98946507b8f8b7b">rep_ref</a>.<a class="code" href="structble__srv__report__ref__t.html#a725a13d8d43f65c0f5e8adc271f71573">report_id</a>   = 0;
<a name="l00463"></a>00463     p_output_report-&gt;<a class="code" href="structble__hids__outp__rep__init__t.html#a070c6ac5d77d97faf98946507b8f8b7b">rep_ref</a>.<a class="code" href="structble__srv__report__ref__t.html#a082cbd2ab34b2f8c1afaf98b3b19fac0">report_type</a> = BLE_HIDS_REP_TYPE_OUTPUT;
<a name="l00464"></a>00464     
<a name="l00465"></a>00465     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;p_output_report-&gt;<a class="code" href="structble__hids__outp__rep__init__t.html#a7affa6c39815d70e8fe83c9b12b9c263">attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00466"></a>00466     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;p_output_report-&gt;<a class="code" href="structble__hids__outp__rep__init__t.html#a7affa6c39815d70e8fe83c9b12b9c263">attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00467"></a>00467 
<a name="l00468"></a>00468     hid_info_flags = HID_INFO_FLAG_REMOTE_WAKE_MSK | HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK;
<a name="l00469"></a>00469 
<a name="l00470"></a>00470     memset(&amp;hids_init_obj, 0, <span class="keyword">sizeof</span>(hids_init_obj));
<a name="l00471"></a>00471 
<a name="l00472"></a>00472     hids_init_obj.<a class="code" href="structble__hids__init__t.html#aec4ea916000444b65d161b03d078386b">evt_handler</a>                    = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaacd557e6bc45d33880a272b051f7684e" title="HID event handler.">on_hids_evt</a>;
<a name="l00473"></a>00473     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>                  = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga54ab546c90d69e5fc9cfee653024ea53" title="Service error handler.">service_error_handler</a>;
<a name="l00474"></a>00474     hids_init_obj.<a class="code" href="structble__hids__init__t.html#ae213e686ada9be3db5d0145cafa44299">is_kb</a>                          = <span class="keyword">true</span>;
<a name="l00475"></a>00475     hids_init_obj.<a class="code" href="structble__hids__init__t.html#ac5f51b1716e007423b10547f000a6bfa">is_mouse</a>                       = <span class="keyword">false</span>;
<a name="l00476"></a>00476     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a6779c4c746ce0d2b8aea6d532e6ad46d">inp_rep_count</a>                  = 1;
<a name="l00477"></a>00477     hids_init_obj.<a class="code" href="structble__hids__init__t.html#ace337c61c33de48831b81df503231cd2">p_inp_rep_array</a>                = input_report_array;
<a name="l00478"></a>00478     hids_init_obj.<a class="code" href="structble__hids__init__t.html#ac502f18e0e0fb7c42ae9ba83de452e39">outp_rep_count</a>                 = 1;
<a name="l00479"></a>00479     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a802761ce4dffd4e4cb45154c1a65790a">p_outp_rep_array</a>               = output_report_array;
<a name="l00480"></a>00480     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a188334a4e9d4695a90263e843b9985a3">feature_rep_count</a>              = 0;
<a name="l00481"></a>00481     hids_init_obj.<a class="code" href="structble__hids__init__t.html#ad9bde41a48b05ac0c04ac8660e7ee9c3">p_feature_rep_array</a>            = NULL;
<a name="l00482"></a>00482     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a185212c529a0c80d609800ecdfd9aef5">rep_map</a>.<a class="code" href="structble__hids__rep__map__init__t.html#ac78cff7af99787faad2a285dffdde08e">data_len</a>               = <span class="keyword">sizeof</span>(report_map_data);
<a name="l00483"></a>00483     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a185212c529a0c80d609800ecdfd9aef5">rep_map</a>.<a class="code" href="structble__hids__rep__map__init__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>                 = report_map_data;
<a name="l00484"></a>00484     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a883ca268e11cefa978f61749ebb21961">is_boot_kb_inp_rep_writable</a>    = <span class="keyword">false</span>;
<a name="l00485"></a>00485     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a504aafb4fb510eb9e2d1905f388695f5">is_boot_mouse_inp_rep_writable</a> = <span class="keyword">false</span>;
<a name="l00486"></a>00486     hids_init_obj.<a class="code" href="structble__hids__init__t.html#aabc2c6085c0d6caccf6ff29021c1d126">hid_information</a>.<a class="code" href="structble__hids__hid__information__t.html#a2a011dc5c6b8855b97d33d0e301a63ab">bcd_hid</a>        = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga86d9879e1f1e698d670d31c933e5fe95">BASE_USB_HID_SPEC_VERSION</a>;
<a name="l00487"></a>00487     hids_init_obj.<a class="code" href="structble__hids__init__t.html#aabc2c6085c0d6caccf6ff29021c1d126">hid_information</a>.<a class="code" href="structble__hids__hid__information__t.html#aec71958133a703cd76e766e8e3b26143">b_country_code</a> = 0;
<a name="l00488"></a>00488     hids_init_obj.<a class="code" href="structble__hids__init__t.html#aabc2c6085c0d6caccf6ff29021c1d126">hid_information</a>.<a class="code" href="structble__hids__hid__information__t.html#aa2585d779da0ab21273a8d92de9a0ebe">flags</a>          = hid_info_flags;
<a name="l00489"></a>00489     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a4939f849bfe8f354935e82db0c37e500">included_services_count</a>        = 0;
<a name="l00490"></a>00490     hids_init_obj.<a class="code" href="structble__hids__init__t.html#a2da787144c7b5ec4bf22c8d02d0a3186">p_included_services_array</a>      = NULL;
<a name="l00491"></a>00491 
<a name="l00492"></a>00492     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a185212c529a0c80d609800ecdfd9aef5">rep_map</a>.<a class="code" href="structble__hids__rep__map__init__t.html#addddaca40513d1c3357ded4f527fda06">rep_map_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00493"></a>00493     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a185212c529a0c80d609800ecdfd9aef5">rep_map</a>.<a class="code" href="structble__hids__rep__map__init__t.html#addddaca40513d1c3357ded4f527fda06">rep_map_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00494"></a>00494     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#aabc2c6085c0d6caccf6ff29021c1d126">hid_information</a>.<a class="code" href="structble__hids__hid__information__t.html#adbc2c94f45ebf2c86646573e90e9969a">char_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00495"></a>00495     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#aabc2c6085c0d6caccf6ff29021c1d126">hid_information</a>.<a class="code" href="structble__hids__hid__information__t.html#adbc2c94f45ebf2c86646573e90e9969a">char_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00496"></a>00496 
<a name="l00497"></a>00497     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a7600fbb6e31c2a49df7d9ee00d0ed8ef">hids_boot_kb_inp_rep</a>.cccd_write_perm);
<a name="l00498"></a>00498     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a7600fbb6e31c2a49df7d9ee00d0ed8ef">hids_boot_kb_inp_rep</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00499"></a>00499     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a7600fbb6e31c2a49df7d9ee00d0ed8ef">hids_boot_kb_inp_rep</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00500"></a>00500     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#aefb8bcf73c4b8d2ce0e483c14fcb84c5">hids_boot_kb_outp_rep</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00501"></a>00501     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#aefb8bcf73c4b8d2ce0e483c14fcb84c5">hids_boot_kb_outp_rep</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00502"></a>00502 
<a name="l00503"></a>00503     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#ade56d45b12aac7e9a01a3eb229a4d46a">hids_protocol_mode_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00504"></a>00504     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#ade56d45b12aac7e9a01a3eb229a4d46a">hids_protocol_mode_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00505"></a>00505     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a41612c278036c148c70940b2ec5c2787">hids_ctrl_point</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00506"></a>00506     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga99f7b13b3c63bcaffe700c9f28c3ee3f" title="Set sec_mode pointed to by ptr to require encryption, but no MITM protection.">BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM</a>(&amp;hids_init_obj.<a class="code" href="structble__hids__init__t.html#a41612c278036c148c70940b2ec5c2787">hids_ctrl_point</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00507"></a>00507 
<a name="l00508"></a>00508     err_code = <a class="code" href="group__ble__sdk__srv__hids.html#gaf0b5ac4400c5c10be0a32554a6ffb68a" title="Initialize the HID Service.">ble_hids_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>, &amp;hids_init_obj);
<a name="l00509"></a>00509     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00510"></a>00510     {
<a name="l00511"></a>00511         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00512"></a>00512     }
<a name="l00513"></a>00513 }
<a name="l00514"></a>00514 
<a name="l00515"></a>00515 
<a name="l00518"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2">00518</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>(<span class="keywordtype">void</span>)
<a name="l00519"></a>00519 {
<a name="l00520"></a>00520     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga2d0743f12929b17b64c5c2fb101a9350" title="Initialize Device Information Service.">dis_init</a>();
<a name="l00521"></a>00521     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga46507354f43dd16b32281f032e29d9c5" title="Initialize Battery Service.">bas_init</a>();
<a name="l00522"></a>00522     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga1469fa1057d51643d5b64abadf23e135" title="Initialize HID Service.">hids_init</a>();
<a name="l00523"></a>00523 }
<a name="l00524"></a>00524 
<a name="l00525"></a>00525 
<a name="l00528"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e">00528</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e" title="Initialize the battery sensor simulator.">sensor_sim_init</a>(<span class="keywordtype">void</span>)
<a name="l00529"></a>00529 {
<a name="l00530"></a>00530     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a0de4531998c77245b8866f2ba909d0fa">min</a>          = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga59eb06cba38be11278ebd2829e95bc26">MIN_BATTERY_LEVEL</a>;
<a name="l00531"></a>00531     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a43e74ba18dc1a237d9f7737ce8df350e">max</a>          = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga16896fb7a69ca90a4a4e341d5a888002">MAX_BATTERY_LEVEL</a>;
<a name="l00532"></a>00532     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a4eed0a83fb9e9824223f835e2b7b3032">incr</a>         = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga69eef02165834e4dabc5757b82dddbf1">BATTERY_LEVEL_INCREMENT</a>;
<a name="l00533"></a>00533     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>.<a class="code" href="structble__sensorsim__cfg__t.html#a91158ca4700058aaa6a54de96b67146a">start_at_max</a> = <span class="keyword">true</span>;
<a name="l00534"></a>00534 
<a name="l00535"></a>00535     <a class="code" href="group__ble__sdk__lib__sensorsim.html#ga87dbeaec725800b329897a89763da807" title="Initialize a triangular waveform sensor simulator.">ble_sensorsim_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa51f5fc284e1b7e1570ab742fa9b63f3">s_battery_sim_state</a>, &amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa752585d9b405d6e0c6fd392d7f64b59">s_battery_sim_cfg</a>);
<a name="l00536"></a>00536 }
<a name="l00537"></a>00537 
<a name="l00538"></a>00538 
<a name="l00541"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga9f11118fb9ce22ad1afe20af6f89b131">00541</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00542"></a>00542 {
<a name="l00543"></a>00543     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>      = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7c1fffb0f865552108560d4c63b32db1">SEC_PARAM_TIMEOUT</a>;
<a name="l00544"></a>00544     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a3d9eee3a6a1d710b0e5d13b567675694">bond</a>         = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gacbf03a82593c273743a5a80a1119b851">SEC_PARAM_BOND</a>;
<a name="l00545"></a>00545     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a808e5ec85cf1656a05a985386ba29276">mitm</a>         = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab6831ebe113f8afe970326b7742b5947">SEC_PARAM_MITM</a>;
<a name="l00546"></a>00546     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a81d248b843331e8798478feecf4f4c92">io_caps</a>      = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga42df85b3a4083cdc614d9111d580d98f">SEC_PARAM_IO_CAPABILITIES</a>;
<a name="l00547"></a>00547     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a01318f39f3b3471bd44bf2f322331788">oob</a>          = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">SEC_PARAM_OOB</a>;  
<a name="l00548"></a>00548     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a66c3e526aae4ca7f3212ae207225b0a2">min_key_size</a> = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">SEC_PARAM_MIN_KEY_SIZE</a>;
<a name="l00549"></a>00549     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a43d814618fbf7f63a318966dd84746c2">max_key_size</a> = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf2cd1595de153ea1d6d843619a1a7707">SEC_PARAM_MAX_KEY_SIZE</a>;
<a name="l00550"></a>00550 }
<a name="l00551"></a>00551 
<a name="l00552"></a>00552 
<a name="l00557"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa">00557</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>(uint32_t nrf_error)
<a name="l00558"></a>00558 {
<a name="l00559"></a>00559     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00560"></a>00560 }
<a name="l00561"></a>00561 
<a name="l00562"></a>00562 
<a name="l00565"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf61b6c1c47f5c96b169ff81c345d7849">00565</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00566"></a>00566 {
<a name="l00567"></a>00567     uint32_t               err_code;
<a name="l00568"></a>00568     <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> cp_init;
<a name="l00569"></a>00569     <a class="code" href="structble__hids__rep__char__t.html" title="HID Report characteristic structure. This contains various information for initialization of a Report...">ble_hids_rep_char_t</a>    input_rep_char = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>.<a class="code" href="structble__hids__s.html#a713a274bad390986573cebcf8f310fd9">inp_rep_array</a>[<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga457a0e46397da8d5efadd01f8709ba24">INPUT_REPORT_KEYS_INDEX</a>];
<a name="l00570"></a>00570     
<a name="l00571"></a>00571     memset(&amp;cp_init, 0, <span class="keyword">sizeof</span>(cp_init));
<a name="l00572"></a>00572 
<a name="l00573"></a>00573     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a>                  = NULL;
<a name="l00574"></a>00574     cp_init.<a class="code" href="structble__conn__params__init__t.html#a915702f42f9a0316745403644d385f22">first_conn_params_update_delay</a> = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">FIRST_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00575"></a>00575     cp_init.<a class="code" href="structble__conn__params__init__t.html#a9bcd0621fbb5f4554f1fafd0b15dc61b">next_conn_params_update_delay</a>  = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadf85796ef07632ed27e0bce9509d9245">NEXT_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00576"></a>00576     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab3c0944561623d4a8da622b18867aafb">max_conn_params_update_count</a>   = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">MAX_CONN_PARAMS_UPDATE_COUNT</a>;
<a name="l00577"></a>00577     cp_init.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a>    = input_rep_char.<a class="code" href="structble__hids__rep__char__t.html#aee1cb1e27b722ea969623de53f101e86">char_handles</a>.<a class="code" href="structble__gatts__char__handles__t.html#a2c7796d4eb58c25a1a724bcd9d5bf183">cccd_handle</a>;
<a name="l00578"></a>00578     cp_init.<a class="code" href="structble__conn__params__init__t.html#a7a3f3aac03305ef8012ade05399b5449">disconnect_on_fail</a>             = <span class="keyword">false</span>;
<a name="l00579"></a>00579     cp_init.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a>                    = NULL;
<a name="l00580"></a>00580     cp_init.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>                  = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>;
<a name="l00581"></a>00581     
<a name="l00582"></a>00582     err_code = <a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080" title="Initialize the Connection Parameters module.">ble_conn_params_init</a>(&amp;cp_init);
<a name="l00583"></a>00583     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00584"></a>00584     {
<a name="l00585"></a>00585         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00586"></a>00586     }
<a name="l00587"></a>00587 }
<a name="l00588"></a>00588 
<a name="l00589"></a>00589 
<a name="l00592"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab7e1400dcd1b0f9470d20af86077ba74">00592</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab7e1400dcd1b0f9470d20af86077ba74" title="Start timers.">timers_start</a>(<span class="keywordtype">void</span>)
<a name="l00593"></a>00593 {
<a name="l00594"></a>00594     uint32_t err_code;
<a name="l00595"></a>00595     
<a name="l00596"></a>00596     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_BATTERY_LEVEL_MEAS, 
<a name="l00597"></a>00597                                <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>, 
<a name="l00598"></a>00598                                <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">BATTERY_LEVEL_MEAS_INTERVAL</a>, 
<a name="l00599"></a>00599                                APP_TIMER_MODE_REPEATED, 
<a name="l00600"></a>00600                                APP_SCHED_QUEUE_LOW_PRI);
<a name="l00601"></a>00601     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00602"></a>00602     {
<a name="l00603"></a>00603         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00604"></a>00604     }
<a name="l00605"></a>00605 }
<a name="l00606"></a>00606 
<a name="l00607"></a>00607 
<a name="l00610"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadf80cd84ee702e57a2a416fe4f653eb8">00610</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>(<span class="keywordtype">void</span>)
<a name="l00611"></a>00611 {
<a name="l00612"></a>00612     uint32_t             err_code;
<a name="l00613"></a>00613     <a class="code" href="structble__gap__adv__params__t.html" title="GAP advertising parameters.">ble_gap_adv_params_t</a> adv_params;
<a name="l00614"></a>00614 
<a name="l00615"></a>00615     <span class="comment">// Start advertising</span>
<a name="l00616"></a>00616     memset(&amp;adv_params, 0, <span class="keyword">sizeof</span>(adv_params));
<a name="l00617"></a>00617 
<a name="l00618"></a>00618     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a>        = <a class="code" href="group___b_l_e___g_a_p___a_d_v___t_y_p_e_s.html#ga6cc0db53453977ee0a31e59f07de2b86">BLE_GAP_ADV_TYPE_ADV_IND</a>;
<a name="l00619"></a>00619     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a27909d1b865548f236a871af2b6aa584">p_peer_addr</a> = NULL;
<a name="l00620"></a>00620     adv_params.<a class="code" href="structble__gap__adv__params__t.html#aefdab55ee0f22565a03a14d09cc71d12">fp</a>          = <a class="code" href="group___b_l_e___g_a_p___a_d_v___f_i_l_t_e_r___p_o_l_i_c_i_e_s.html#ga0b0393df73db101d6cbfaede2dbb7ea6">BLE_GAP_ADV_FP_ANY</a>;
<a name="l00621"></a>00621     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a6c52a3d605c056768b59164ce8df8334">interval</a>    = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">APP_ADV_INTERVAL</a>;
<a name="l00622"></a>00622     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>     = <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf58371bad8e1be8e2323df60379ed2df">APP_ADV_TIMEOUT_IN_SECONDS</a>;
<a name="l00623"></a>00623 
<a name="l00624"></a>00624     err_code = <a class="code" href="group___b_l_e___g_a_p.html#gabdbf78c3a8b09c6f2fb92d8733096af8" title="Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).">ble_gap_adv_start</a>(&amp;adv_params);
<a name="l00625"></a>00625     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00626"></a>00626     {
<a name="l00627"></a>00627         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00628"></a>00628     }
<a name="l00629"></a>00629 
<a name="l00630"></a>00630     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ADVERTISING_LED_PIN_NO);
<a name="l00631"></a>00631 }
<a name="l00632"></a>00632 
<a name="l00633"></a>00633 
<a name="l00639"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf3a594648fc886743b8b8c2123724679">00639</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf3a594648fc886743b8b8c2123724679" title="This function will send sample key presses to the peer.">keys_send</a>(uint8_t key_pattern_len, uint8_t * p_key_pattern)
<a name="l00640"></a>00640 {
<a name="l00641"></a>00641     uint32_t err_code;
<a name="l00642"></a>00642 
<a name="l00643"></a>00643     <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gade286b62fde8822965f1e5740a2e9544">s_in_boot_mode</a>)
<a name="l00644"></a>00644     {
<a name="l00645"></a>00645         err_code = <a class="code" href="group__ble__sdk__srv__hids.html#ga30a528bd23ffe8ddea07d1960eb4c507" title="Send Boot Keyboard Input Report.">ble_hids_boot_kb_inp_rep_send</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>, 
<a name="l00646"></a>00646                                                  key_pattern_len, 
<a name="l00647"></a>00647                                                  p_key_pattern);
<a name="l00648"></a>00648         <span class="keywordflow">if</span> (err_code == <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00649"></a>00649         {
<a name="l00650"></a>00650             err_code = <a class="code" href="group__ble__sdk__srv__hids.html#ga30a528bd23ffe8ddea07d1960eb4c507" title="Send Boot Keyboard Input Report.">ble_hids_boot_kb_inp_rep_send</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>, 
<a name="l00651"></a>00651                                                      key_pattern_len, 
<a name="l00652"></a>00652                                                      <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga879ae27a78496d2725f8b8d0481baa38">s_sample_key_release_pattern</a>);
<a name="l00653"></a>00653         }
<a name="l00654"></a>00654     }
<a name="l00655"></a>00655     <span class="keywordflow">else</span>
<a name="l00656"></a>00656     {
<a name="l00657"></a>00657         err_code = <a class="code" href="group__ble__sdk__srv__hids.html#gaebf0c8621a14c15990aeac30750fb5bc" title="Send Input Report.">ble_hids_inp_rep_send</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>,
<a name="l00658"></a>00658                                          <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga457a0e46397da8d5efadd01f8709ba24">INPUT_REPORT_KEYS_INDEX</a>,
<a name="l00659"></a>00659                                          key_pattern_len,
<a name="l00660"></a>00660                                          p_key_pattern);
<a name="l00661"></a>00661         <span class="keywordflow">if</span> (err_code == <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00662"></a>00662         {
<a name="l00663"></a>00663             err_code = <a class="code" href="group__ble__sdk__srv__hids.html#gaebf0c8621a14c15990aeac30750fb5bc" title="Send Input Report.">ble_hids_inp_rep_send</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>,
<a name="l00664"></a>00664                                              <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga457a0e46397da8d5efadd01f8709ba24">INPUT_REPORT_KEYS_INDEX</a>,
<a name="l00665"></a>00665                                              key_pattern_len,
<a name="l00666"></a>00666                                              <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga879ae27a78496d2725f8b8d0481baa38">s_sample_key_release_pattern</a>);
<a name="l00667"></a>00667         }
<a name="l00668"></a>00668     }
<a name="l00669"></a>00669 
<a name="l00670"></a>00670     <span class="keywordflow">if</span> (
<a name="l00671"></a>00671         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00672"></a>00672         &amp;&amp;
<a name="l00673"></a>00673         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>)
<a name="l00674"></a>00674         &amp;&amp;
<a name="l00675"></a>00675         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00676"></a>00676         &amp;&amp;
<a name="l00677"></a>00677         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00678"></a>00678        )
<a name="l00679"></a>00679     {
<a name="l00680"></a>00680         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00681"></a>00681     }
<a name="l00682"></a>00682 }
<a name="l00683"></a>00683 
<a name="l00684"></a>00684 
<a name="l00689"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gac41fd9d5a200157e47c2aa27d328074e">00689</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gac41fd9d5a200157e47c2aa27d328074e" title="HID Report Characteristic Write event handler.">on_hid_rep_char_write</a>(<a class="code" href="structble__hids__evt__t.html" title="HID Service event.">ble_hids_evt_t</a> *p_evt)
<a name="l00690"></a>00690 {
<a name="l00691"></a>00691     <span class="keywordflow">if</span> (p_evt-&gt;params.char_write.char_id.rep_type == BLE_HIDS_REP_TYPE_OUTPUT)
<a name="l00692"></a>00692     {
<a name="l00693"></a>00693         uint32_t err_code;
<a name="l00694"></a>00694         uint8_t  report_val;
<a name="l00695"></a>00695         uint8_t  report_index = p_evt-&gt;params.char_write.char_id.rep_index;
<a name="l00696"></a>00696         
<a name="l00697"></a>00697         <span class="keywordflow">if</span> (report_index == <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga99efaf34830368d0abd515e02247c2c7">OUTPUT_REPORT_INDEX</a>)
<a name="l00698"></a>00698         {
<a name="l00699"></a>00699             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga618a599e2a493e7e5e21ec6712eab629">OUTPUT_REPORT_MAX_LEN</a> == 1);
<a name="l00700"></a>00700 
<a name="l00701"></a>00701             err_code = <a class="code" href="group__ble__sdk__srv__hids.html#ga66e5fb9cefb62e76a88f2cc229c55f70" title="Get the current value of Output Report from the stack.">ble_hids_outp_rep_get</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>, 
<a name="l00702"></a>00702                                              report_index, 
<a name="l00703"></a>00703                                              <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga618a599e2a493e7e5e21ec6712eab629">OUTPUT_REPORT_MAX_LEN</a>, 
<a name="l00704"></a>00704                                              0,
<a name="l00705"></a>00705                                              &amp;report_val);
<a name="l00706"></a>00706             <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00707"></a>00707             {
<a name="l00708"></a>00708                 <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00709"></a>00709             }
<a name="l00710"></a>00710 
<a name="l00711"></a>00711             <span class="keywordflow">if</span> ((report_val &amp; <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gae4da404b343c895fbbb187de7c9d5d8e">OUTPUT_REPORT_BIT_MASK_CAPS_LOCK</a>) != 0)
<a name="l00712"></a>00712             {
<a name="l00713"></a>00713                 <span class="comment">// Caps Lock On</span>
<a name="l00714"></a>00714                 <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5d49591a87319c84e9963e355aa66e50">CAPS_ON_LED_PIN_NO</a>);
<a name="l00715"></a>00715                 <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf3a594648fc886743b8b8c2123724679" title="This function will send sample key presses to the peer.">keys_send</a>(<span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf4f08291880f002aa1739475ff1f64cb">s_caps_on_key_pattern</a>), <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf4f08291880f002aa1739475ff1f64cb">s_caps_on_key_pattern</a>);
<a name="l00716"></a>00716             }
<a name="l00717"></a>00717             <span class="keywordflow">else</span>
<a name="l00718"></a>00718             {
<a name="l00719"></a>00719                 <span class="comment">// Caps Lock Off</span>
<a name="l00720"></a>00720                 <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5d49591a87319c84e9963e355aa66e50">CAPS_ON_LED_PIN_NO</a>);
<a name="l00721"></a>00721                 <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf3a594648fc886743b8b8c2123724679" title="This function will send sample key presses to the peer.">keys_send</a>(<span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad755d5a2e1c883ec7fc9548a369049cb">s_caps_off_key_pattern</a>), <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad755d5a2e1c883ec7fc9548a369049cb">s_caps_off_key_pattern</a>);
<a name="l00722"></a>00722             }
<a name="l00723"></a>00723         }
<a name="l00724"></a>00724     }
<a name="l00725"></a>00725 }
<a name="l00726"></a>00726 
<a name="l00727"></a>00727 
<a name="l00735"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaacd557e6bc45d33880a272b051f7684e">00735</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaacd557e6bc45d33880a272b051f7684e" title="HID event handler.">on_hids_evt</a>(<a class="code" href="structble__hids__s.html" title="HID Service structure. This contains various status information for the service.">ble_hids_t</a> * p_hids, <a class="code" href="structble__hids__evt__t.html" title="HID Service event.">ble_hids_evt_t</a> *p_evt)
<a name="l00736"></a>00736 {
<a name="l00737"></a>00737     <span class="keywordflow">switch</span> (p_evt-&gt;<a class="code" href="structble__hids__evt__t.html#a1cd4bcc9aa3fde6718c5bcebfdbed672">evt_type</a>)
<a name="l00738"></a>00738     {
<a name="l00739"></a>00739         <span class="keywordflow">case</span> <a class="code" href="group__ble__sdk__srv__hids.html#gga621d899fc96687c922a0c65010bfc063a4bc01306b5a8d12443926c1761d49a3a">BLE_HIDS_EVT_BOOT_MODE_ENTERED</a>:
<a name="l00740"></a>00740             <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gade286b62fde8822965f1e5740a2e9544">s_in_boot_mode</a> = <span class="keyword">true</span>;
<a name="l00741"></a>00741             <span class="keywordflow">break</span>;
<a name="l00742"></a>00742 
<a name="l00743"></a>00743         <span class="keywordflow">case</span> <a class="code" href="group__ble__sdk__srv__hids.html#gga621d899fc96687c922a0c65010bfc063a42845071ff0875e098bd16723d57d72f">BLE_HIDS_EVT_REPORT_MODE_ENTERED</a>:
<a name="l00744"></a>00744             <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gade286b62fde8822965f1e5740a2e9544">s_in_boot_mode</a> = <span class="keyword">false</span>;
<a name="l00745"></a>00745             <span class="keywordflow">break</span>;
<a name="l00746"></a>00746 
<a name="l00747"></a>00747         <span class="keywordflow">case</span> <a class="code" href="group__ble__sdk__srv__hids.html#gga621d899fc96687c922a0c65010bfc063a0afaaafa6865acd5725096b6c2f6faa6">BLE_HIDS_EVT_REP_CHAR_WRITE</a>:
<a name="l00748"></a>00748             <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gac41fd9d5a200157e47c2aa27d328074e" title="HID Report Characteristic Write event handler.">on_hid_rep_char_write</a>(p_evt);
<a name="l00749"></a>00749             <span class="keywordflow">break</span>;
<a name="l00750"></a>00750 
<a name="l00751"></a>00751         <span class="keywordflow">default</span>:
<a name="l00752"></a>00752             <span class="keywordflow">break</span>;
<a name="l00753"></a>00753     }
<a name="l00754"></a>00754 }
<a name="l00755"></a>00755 
<a name="l00756"></a>00756 
<a name="l00761"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9">00761</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00762"></a>00762 {
<a name="l00763"></a>00763     uint32_t                         err_code = <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00764"></a>00764     <span class="keyword">static</span> uint16_t                  <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00765"></a>00765     <span class="keyword">static</span> <a class="code" href="structble__gap__evt__auth__status__t.html" title="Event data for authentication status event.">ble_gap_evt_auth_status_t</a> s_auth_status;
<a name="l00766"></a>00766     <a class="code" href="structble__gap__enc__info__t.html" title="GAP Encryption Information.">ble_gap_enc_info_t</a> *             p_enc_info;
<a name="l00767"></a>00767 
<a name="l00768"></a>00768     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00769"></a>00769     {
<a name="l00770"></a>00770         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00771"></a>00771             <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(CONNECTED_LED_PIN_NO);
<a name="l00772"></a>00772             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00773"></a>00773             s_conn_handle = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.<a class="code" href="structble__gatts__evt__t.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>;
<a name="l00774"></a>00774             <span class="keywordflow">break</span>;
<a name="l00775"></a>00775 
<a name="l00776"></a>00776         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00777"></a>00777             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(CONNECTED_LED_PIN_NO);
<a name="l00778"></a>00778             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5d49591a87319c84e9963e355aa66e50">CAPS_ON_LED_PIN_NO</a>);
<a name="l00779"></a>00779             s_conn_handle = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00780"></a>00780             <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l00781"></a>00781             <span class="keywordflow">break</span>;
<a name="l00782"></a>00782 
<a name="l00783"></a>00783         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da6c5eefbcfabbc1ce4a8bcbf550c285ae">BLE_GAP_EVT_SEC_PARAMS_REQUEST</a>:
<a name="l00784"></a>00784             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga5339c2562371354a0e3752b86214b92a" title="Reply with GAP security parameters.">ble_gap_sec_params_reply</a>(s_conn_handle, 
<a name="l00785"></a>00785                                                 <a class="code" href="group___b_l_e___g_a_p___s_e_c___s_t_a_t_u_s.html#gaa0334dea24e449e5c28c88bbe8a1d00f">BLE_GAP_SEC_STATUS_SUCCESS</a>,
<a name="l00786"></a>00786                                                 &amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>);
<a name="l00787"></a>00787             <span class="keywordflow">break</span>;
<a name="l00788"></a>00788 
<a name="l00789"></a>00789         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gga80155586fa275b28773c9b203f52cabaae3776204f11a583e105aed0e477601da">BLE_GATTS_EVT_SYS_ATTR_MISSING</a>:
<a name="l00790"></a>00790             err_code = <a class="code" href="group___b_l_e___g_a_t_t_s.html#ga65ae169e49530eb2fa4bf73053060a13" title="Update persistent system attribute info.">ble_gatts_sys_attr_set</a>(s_conn_handle, NULL, 0);
<a name="l00791"></a>00791             <span class="keywordflow">break</span>;
<a name="l00792"></a>00792 
<a name="l00793"></a>00793         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da8958220152f7547da3b250b4f724877c">BLE_GAP_EVT_AUTH_STATUS</a>:
<a name="l00794"></a>00794             s_auth_status = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a350f0c3a127499fb3d522d361554e3eb">auth_status</a>;
<a name="l00795"></a>00795             <span class="keywordflow">break</span>;
<a name="l00796"></a>00796 
<a name="l00797"></a>00797         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daf1c60079f92820cb933ebdb66d2d8d7d">BLE_GAP_EVT_SEC_INFO_REQUEST</a>:
<a name="l00798"></a>00798             p_enc_info = &amp;s_auth_status.periph_keys.<a class="code" href="structble__gap__evt__auth__status__t_1_1periph__keys__t.html#a7eee7ec3b96cc86a0080ab368dae817d">enc_info</a>;
<a name="l00799"></a>00799             <span class="keywordflow">if</span> (p_enc_info-&gt;<a class="code" href="structble__gap__enc__info__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a> == p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a5f04f763d053c94297246b6ed351c66a">sec_info_request</a>.<a class="code" href="structble__gap__evt__sec__info__request__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a>)
<a name="l00800"></a>00800             {
<a name="l00801"></a>00801                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(s_conn_handle, p_enc_info, NULL);
<a name="l00802"></a>00802             }
<a name="l00803"></a>00803             <span class="keywordflow">else</span>
<a name="l00804"></a>00804             {
<a name="l00805"></a>00805                 <span class="comment">// No keys found for this device</span>
<a name="l00806"></a>00806                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(s_conn_handle, NULL, NULL);
<a name="l00807"></a>00807             }
<a name="l00808"></a>00808             <span class="keywordflow">break</span>;
<a name="l00809"></a>00809 
<a name="l00810"></a>00810         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da57e5d1061d9b3d1500fb3556a3fb8847">BLE_GAP_EVT_TIMEOUT</a>:
<a name="l00811"></a>00811             <span class="keywordflow">if</span> (p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a17e289da592e731cde1451c2d5f3f24a">timeout</a>.<a class="code" href="structble__gap__evt__timeout__t.html#af5eca485cd2b34522478907d4c8f5bc6">src</a> == <a class="code" href="group___b_l_e___g_a_p___t_i_m_e_o_u_t___t_y_p_e_s.html#gafee7b7095fb21ed922c6719cc1c2d23f">BLE_GAP_TIMEOUT_TYPE_ADVERTISEMENT</a>)
<a name="l00812"></a>00812             { 
<a name="l00813"></a>00813                 <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00814"></a>00814 
<a name="l00815"></a>00815                 <span class="comment">// Go to system-off mode (this function will not return; wakeup will cause a reset)</span>
<a name="l00816"></a>00816                 err_code = <a class="code" href="group__nrf__soc__api.html#ga302701614c7bb1c9fc01dafec2bb04fb" title="Puts the chip in System OFF mode.">nrf_power_system_off</a>();    
<a name="l00817"></a>00817             }
<a name="l00818"></a>00818             <span class="keywordflow">break</span>;
<a name="l00819"></a>00819 
<a name="l00820"></a>00820         <span class="keywordflow">default</span>:
<a name="l00821"></a>00821             <span class="keywordflow">break</span>;
<a name="l00822"></a>00822     }
<a name="l00823"></a>00823 
<a name="l00824"></a>00824     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00825"></a>00825     {
<a name="l00826"></a>00826         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00827"></a>00827     }
<a name="l00828"></a>00828 }
<a name="l00829"></a>00829 
<a name="l00830"></a>00830 
<a name="l00838"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa1927dfd1c321164f2f34ae9ad95a77d">00838</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa1927dfd1c321164f2f34ae9ad95a77d" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>(app_sched_event_data_t * p_ev_data)
<a name="l00839"></a>00839 {
<a name="l00840"></a>00840     <a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt;
<a name="l00841"></a>00841     
<a name="l00842"></a>00842     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(p_ev_data-&gt;event_id == APP_SCHED_EVENT_BLE);
<a name="l00843"></a>00843     
<a name="l00844"></a>00844     p_ble_evt = &amp;p_ev_data-&gt;data.ble.ble_evt;
<a name="l00845"></a>00845 
<a name="l00846"></a>00846     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(p_ble_evt);
<a name="l00847"></a>00847     <a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871" title="BLE stack event handler.">ble_conn_params_on_ble_evt</a>(p_ble_evt);
<a name="l00848"></a>00848     <a class="code" href="group__ble__sdk__srv__hids.html#ga77b3d388f18004a1e730b4f2bbee5cac" title="HID Service BLE stack event handler.">ble_hids_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga39dca3cc11120abf5cbc751bb69d5df0">s_hids</a>, p_ble_evt);
<a name="l00849"></a>00849     <a class="code" href="group__ble__sdk__srv__bas.html#ga01b70d77540660d7e312121d9f1d3b3a" title="Battery Service BLE stack event handler.">ble_bas_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, p_ble_evt);
<a name="l00850"></a>00850 }
<a name="l00851"></a>00851 
<a name="l00852"></a>00852 
<a name="l00860"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gacf1716b2e00b3456f0733e8101ed9e0d">00860</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gacf1716b2e00b3456f0733e8101ed9e0d" title="Pass bluetooth stack event to scheduler.">ble_evt_schedule</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00861"></a>00861 {
<a name="l00862"></a>00862     uint32_t               err_code;
<a name="l00863"></a>00863     app_sched_event_data_t ev_data;
<a name="l00864"></a>00864     
<a name="l00865"></a>00865     ev_data.event_id         = APP_SCHED_EVENT_BLE;
<a name="l00866"></a>00866     ev_data.data.ble.ble_evt = *p_ble_evt;
<a name="l00867"></a>00867     
<a name="l00868"></a>00868     err_code = <a class="code" href="group__app__scheduler.html#gaaecab81ed0f2e9c1ce56586367b93dc5" title="Schedules an event.">app_sched_event_put</a>(&amp;ev_data, <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa1927dfd1c321164f2f34ae9ad95a77d" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>, APP_SCHED_QUEUE_LOW_PRI);
<a name="l00869"></a>00869     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00870"></a>00870     {
<a name="l00871"></a>00871         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00872"></a>00872     }
<a name="l00873"></a>00873 }
<a name="l00874"></a>00874 
<a name="l00875"></a>00875 
<a name="l00880"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a">00880</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>(<span class="keywordtype">void</span>)
<a name="l00881"></a>00881 {
<a name="l00882"></a>00882     uint32_t err_code = <a class="code" href="group__ble__stack__handler.html#gada9282a45a226bbe8544995b2fbf22dd" title="Initialize stack handler module.">ble_stack_handler_init</a>(<a class="code" href="group__nrf__sdm__api.html#ggaaf8fd5f0e57d456151c951e0f3715fc4a1c5e9917211a50eac336a3fd2e467756">NRF_CLOCK_LFCLKSRC_XTAL_20_PPM</a>, <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gacf1716b2e00b3456f0733e8101ed9e0d" title="Pass bluetooth stack event to scheduler.">ble_evt_schedule</a>);
<a name="l00883"></a>00883     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00884"></a>00884     {
<a name="l00885"></a>00885         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00886"></a>00886     }
<a name="l00887"></a>00887 }
<a name="l00888"></a>00888 
<a name="l00889"></a>00889 
<a name="l00897"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gace35358370a1c55df3d12849e15f2c45">00897</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gace35358370a1c55df3d12849e15f2c45" title="Keyboard event handler.">keyboard_event_handler</a>(app_sched_event_data_t *p_ev_data)
<a name="l00898"></a>00898 {
<a name="l00899"></a>00899     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(p_ev_data-&gt;event_id == APP_SCHED_EVENT_KEYBOARD);
<a name="l00900"></a>00900     
<a name="l00901"></a>00901     <span class="comment">// Send sample key pattern</span>
<a name="l00902"></a>00902     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf3a594648fc886743b8b8c2123724679" title="This function will send sample key presses to the peer.">keys_send</a>(<span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa3b8fdf1e5fd735cc1a297820f750f46">s_sample_key_press_pattern</a>), <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa3b8fdf1e5fd735cc1a297820f750f46">s_sample_key_press_pattern</a>);
<a name="l00903"></a>00903 }
<a name="l00904"></a>00904 
<a name="l00905"></a>00905 
<a name="l00911"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga34d488712613dd99626f93304e32d4d4">00911</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga34d488712613dd99626f93304e32d4d4" title="Passes a keyboard event to the Scheduler.">keyboard_event_schedule</a>(<span class="keywordtype">void</span>)
<a name="l00912"></a>00912 {
<a name="l00913"></a>00913     uint32_t               err_code;
<a name="l00914"></a>00914     app_sched_event_data_t ev_data;
<a name="l00915"></a>00915     
<a name="l00916"></a>00916     ev_data.event_id = APP_SCHED_EVENT_KEYBOARD;
<a name="l00917"></a>00917     
<a name="l00918"></a>00918     err_code = <a class="code" href="group__app__scheduler.html#gaaecab81ed0f2e9c1ce56586367b93dc5" title="Schedules an event.">app_sched_event_put</a>(&amp;ev_data, <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gace35358370a1c55df3d12849e15f2c45" title="Keyboard event handler.">keyboard_event_handler</a>, APP_SCHED_QUEUE_LOW_PRI);
<a name="l00919"></a>00919     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00920"></a>00920     {
<a name="l00921"></a>00921         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00922"></a>00922     }
<a name="l00923"></a>00923 }
<a name="l00924"></a>00924 
<a name="l00925"></a>00925 
<a name="l00928"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga26b108e2296d5514a2391960b4231d71">00928</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga26b108e2296d5514a2391960b4231d71" title="GPIOTE interrupt handler.">GPIOTE_IRQHandler</a>(<span class="keywordtype">void</span>)
<a name="l00929"></a>00929 {
<a name="l00930"></a>00930     <span class="keywordflow">if</span> (
<a name="l00931"></a>00931         (NRF_GPIOTE-&gt;EVENTS_PORT != 0)
<a name="l00932"></a>00932         &amp;&amp;
<a name="l00933"></a>00933         ((NRF_GPIOTE-&gt;INTENSET &amp; GPIOTE_INTENSET_PORT_Msk) != 0)
<a name="l00934"></a>00934     )
<a name="l00935"></a>00935     {
<a name="l00936"></a>00936         NRF_GPIOTE-&gt;EVENTS_PORT = 0;
<a name="l00937"></a>00937         <span class="keywordflow">if</span> (<a class="code" href="group__nrf__gpio.html#ga0983906029818d8aa199b71b578d1c12" title="Read the input level of a GPIO pin.">nrf_gpio_pin_read</a>(<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga81bb5458ad79486e6aefb2286239b760">KEY_PRESS_BUTTON_PIN_NO</a>) == 0)
<a name="l00938"></a>00938         {
<a name="l00939"></a>00939             <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga34d488712613dd99626f93304e32d4d4" title="Passes a keyboard event to the Scheduler.">keyboard_event_schedule</a>();
<a name="l00940"></a>00940         }
<a name="l00941"></a>00941     }
<a name="l00942"></a>00942 }
<a name="l00943"></a>00943 
<a name="l00944"></a>00944 
<a name="l00947"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga265c25c068555fbfae4ab4f391060040">00947</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>(<span class="keywordtype">void</span>)
<a name="l00948"></a>00948 {
<a name="l00949"></a>00949     uint32_t err_code;
<a name="l00950"></a>00950     uint32_t per_rdy;
<a name="l00951"></a>00951 
<a name="l00952"></a>00952     <span class="comment">// Power on GPIOTE module</span>
<a name="l00953"></a>00953     err_code = <a class="code" href="group__nrf__soc__api.html#ga4070a6cd178fce204f58a1bf6e3fc954" title="Sets bits in the NRF_POWER-&gt;PERPOWER register.">nrf_power_perpower_set</a>(POWER_PERPOWER_GPIOTE_Msk);
<a name="l00954"></a>00954     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00955"></a>00955     {
<a name="l00956"></a>00956         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00957"></a>00957     }
<a name="l00958"></a>00958 
<a name="l00959"></a>00959     <span class="keywordflow">do</span>
<a name="l00960"></a>00960     {
<a name="l00961"></a>00961         err_code = <a class="code" href="group__nrf__soc__api.html#gabaf2aa42d1d287d9d4fd2b00ecda1da7" title="Get contents of NRF_POWER-&gt;PERRDY register, indicates which peripherals are powered on/off...">nrf_power_perrdy_get</a>(&amp;per_rdy);
<a name="l00962"></a>00962         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00963"></a>00963         {
<a name="l00964"></a>00964             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00965"></a>00965         }
<a name="l00966"></a>00966     } <span class="keywordflow">while</span> ((per_rdy &amp; POWER_PERRDY_GPIOTE_Msk) == 0);
<a name="l00967"></a>00967 
<a name="l00968"></a>00968     <span class="comment">// Initialize GPIOTE module</span>
<a name="l00969"></a>00969     NRF_GPIOTE-&gt;INTENCLR = 0xffffffffUL;
<a name="l00970"></a>00970     NRF_GPIOTE-&gt;INTENSET = GPIOTE_INTENSET_PORT_Msk;
<a name="l00971"></a>00971 
<a name="l00972"></a>00972     <span class="comment">// Configure Button 0. The button will also wake up the application.</span>
<a name="l00973"></a>00973     NRF_GPIO-&gt;PIN_CNF[<a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga81bb5458ad79486e6aefb2286239b760">KEY_PRESS_BUTTON_PIN_NO</a>] =
<a name="l00974"></a>00974                                           (GPIO_PIN_CNF_DIR_Input     &lt;&lt; GPIO_PIN_CNF_DIR_Pos)    |
<a name="l00975"></a>00975                                           (GPIO_PIN_CNF_INPUT_Connect &lt;&lt; GPIO_PIN_CNF_INPUT_Pos)  |
<a name="l00976"></a>00976                                           (GPIO_PIN_CNF_PULL_Disabled &lt;&lt; GPIO_PIN_CNF_PULL_Pos)   |
<a name="l00977"></a>00977                                           (GPIO_PIN_CNF_DRIVE_S0S1    &lt;&lt; GPIO_PIN_CNF_DRIVE_Pos)  |
<a name="l00978"></a>00978                                           (GPIO_PIN_CNF_SENSE_Low     &lt;&lt; GPIO_PIN_CNF_SENSE_Pos);
<a name="l00979"></a>00979                                           
<a name="l00980"></a>00980     err_code = <a class="code" href="group__nrf__soc__api.html#ga444796a3a1fc91db087ceebcd92d6561" title="Clear Pending Interrupt.">nrf_nvic_ClearPendingIRQ</a>(GPIOTE_IRQn);
<a name="l00981"></a>00981     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00982"></a>00982     {
<a name="l00983"></a>00983         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00984"></a>00984     }
<a name="l00985"></a>00985 
<a name="l00986"></a>00986     err_code = <a class="code" href="group__nrf__soc__api.html#gad1a939313c86ac881a0b1043715ef475" title="Set Interrupt Priority.">nrf_nvic_SetPriority</a>(GPIOTE_IRQn, NRF_APP_PRIORITY_LOW);
<a name="l00987"></a>00987     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00988"></a>00988     {
<a name="l00989"></a>00989         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00990"></a>00990     }
<a name="l00991"></a>00991 
<a name="l00992"></a>00992     err_code = <a class="code" href="group__nrf__soc__api.html#ga624ecb710ec5cdaf22893608d55c6f3a" title="Enable External Interrupt.">nrf_nvic_EnableIRQ</a>(GPIOTE_IRQn);
<a name="l00993"></a>00993     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00994"></a>00994     {
<a name="l00995"></a>00995         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00996"></a>00996     }
<a name="l00997"></a>00997 }
<a name="l00998"></a>00998 
<a name="l00999"></a>00999 
<a name="l01002"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga3adda2642702fdb99b08992c39494000">01002</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>(<span class="keywordtype">void</span>)
<a name="l01003"></a>01003 {
<a name="l01004"></a>01004     uint32_t err_code = <a class="code" href="group__nrf__soc__api.html#ga2aae5f388f1b6179058c62e2fb05a547" title="Waits for an application event.">nrf_wait_for_app_event</a>();
<a name="l01005"></a>01005     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l01006"></a>01006     {
<a name="l01007"></a>01007         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l01008"></a>01008     }
<a name="l01009"></a>01009 }
<a name="l01010"></a>01010 
<a name="l01011"></a>01011 
<a name="l01014"></a><a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga840291bc02cba5474a4cb46a9b9566fe">01014</a> <span class="keywordtype">int</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#ga840291bc02cba5474a4cb46a9b9566fe" title="Application main function.">main</a>(<span class="keywordtype">void</span>)
<a name="l01015"></a>01015 {
<a name="l01016"></a>01016     <span class="comment">// Initialize</span>
<a name="l01017"></a>01017     <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>();
<a name="l01018"></a>01018     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>();
<a name="l01019"></a>01019     <a class="code" href="group__app__scheduler.html#ga62e8131bc306582c34e1db7565f08a81" title="Initializes the Scheduler.">app_sched_init</a>();
<a name="l01020"></a>01020     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>();
<a name="l01021"></a>01021     <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>();
<a name="l01022"></a>01022     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>();
<a name="l01023"></a>01023     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>();
<a name="l01024"></a>01024     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>();
<a name="l01025"></a>01025     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga6f75e3fe8d4ed6400f9429987dee0f3e" title="Initialize the battery sensor simulator.">sensor_sim_init</a>();
<a name="l01026"></a>01026     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>();
<a name="l01027"></a>01027     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>();
<a name="l01028"></a>01028     
<a name="l01029"></a>01029     <span class="comment">// Start execution</span>
<a name="l01030"></a>01030     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gab7e1400dcd1b0f9470d20af86077ba74" title="Start timers.">timers_start</a>();
<a name="l01031"></a>01031     <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l01032"></a>01032     
<a name="l01033"></a>01033     <span class="comment">// Enter main loop</span>
<a name="l01034"></a>01034     <span class="keywordflow">for</span> (;;)
<a name="l01035"></a>01035     {
<a name="l01036"></a>01036         <a class="code" href="group__app__scheduler.html#ga6fd6a3db7526418f796c55c096360ded" title="Executes all scheduled events.">app_sched_schedule</a>();
<a name="l01037"></a>01037         <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>();
<a name="l01038"></a>01038     }
<a name="l01039"></a>01039 }
<a name="l01040"></a>01040 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="nrf6310__nrf2752_2ble_2ble__app__hids__keyboard_2main_8c.html">main.c</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
